<?php
// +----------------------------------------------------------------------
// | Description: 客户
// +----------------------------------------------------------------------
// | Author: zl
// +----------------------------------------------------------------------

namespace app\crm\controller;

use app\admin\controller\ApiCommon;
use app\crm\model\BalanceLog;
use app\crm\model\Setting;
use app\crm\model\SettingCategory;
use app\crm\model\Service;
use app\crm\model\ReturnVist;
use app\crm\model\ReturnVistT;
use app\crm\model\ProductAnalysisModel;
use app\crm\model\Customer as CustomerModel;
use app\crm\model\TransferShop;
use app\crm\model\CustomerConfig as CustomerConfigModel;
use app\crm\model\CustomerGrade as CustomerGradeModel;
use think\response\Json;
use think\facade\Db;
use Kingdee\Kingdee;
class ProductAnalysisTj extends ApiCommon
{
    protected $customerModel;
    protected $customerConfigModel;
    /**
     * 用于判断权限
     * @permission 无限制
     * @allow 登录用户可访问
     * @other 其他根据系统设置
     **/
    public function initialize()
    {
        $action = [
            'permission' => ['house_list','setcustomerage','setzycustomer'],
            'allow' => ['users', 'info']
        ];
        event('CheckAuth',$action);
        $request = $this->request;
        $a = strtolower($request->action());

        $this->customerModel = new CustomerModel();
        $this->customerConfigModel = new CustomerConfigModel();
        if (!in_array($a, $action['permission'])) {
            parent::initialize();
        }
    }
    
	/**
	 * 品项分析数据报表
	 * @param  CustomerModel $customerModel
	 * @return Json
	 */
	public function setProductAnalysis(CustomerModel $customerModel): Json
	{
		
	    $shopIds = $this->getCommonShopIdsCollectByUserType();
	    $this->param['shopIds'] = $shopIds;
	    $this->param['user_id'] = $this->userInfo['id'];

	    $productModel = new ProductAnalysisModel();
	    $data = $productModel->getProductList($this->param);
	   
	    if (!$data) {
	        return resultArray(['error' => $customerModel->getError()]);
	    }
	    return resultArray(['data' => $data]);
	}
	
	public function setOrderGoodsAnalyse()
	{
		$productModel = new ProductAnalysisModel();
	    $data = $productModel->setOrderGoodsAnalyse($this->param);
	}
	/**
	 * 查看门店品项分析数据报表明细
	 * @author ran
	 * @date 2022-12-28 15:27
	 * mailbox 827918821@qq.com
	 */
	public function getShopProductList(){
	    $request = $this->request->param();
		
	    $model = new ProductAnalysisModel();
	    $res          = $model->getShopProductList((int)$request['shopId'],(int)$request['page'],(int)$request['limit'],$request);
	    return $this->success($res,'获取资源成功');
	}

	public function getGoodsList(){
		$model = new ProductAnalysisModel();
	    $res          = $model->getGoodsList();
	    return $this->success($res,'获取资源成功');
	}
	
}
